//
//  OneCell.m
//  CellFactoryModel
//
//  Created by 向祖华 on 16/4/22.
//  Copyright © 2016年 向祖华. All rights reserved.
//

#import "OneCell.h"

static NSInteger cellHeight = 0;

@implementation OneCell
//返回细胞
-(RootTableViewCell*)initWithDataModel:(DataModel*)model{
    self.backgroundColor = [UIColor brownColor];
    //设置标题文字
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 30)];
    self.lable.text = model.title;
    [self addSubview:self.lable];
    UIImage *image = [UIImage imageNamed:model.imageOneName];
    //判断数据中是否有标题文字，以便确定图片的位置
    CGRect imageRect;
    if ([model.title length]==0) {
        self.lable.hidden = YES;
        imageRect = CGRectMake(0, 0, kScreenW , (kScreenW/image.size.width)*image.size.height);
    } else {
        self.lable.hidden = NO;
        imageRect = CGRectMake(0, 40, kScreenW , (kScreenW/image.size.width)*image.size.height);
    }
    self.imageV = [[UIImageView alloc] initWithFrame:imageRect];
    self.imageV.image = image;
    [self addSubview:self.imageV];
    //获取self所需要的最大Y值，即为该细胞的高度
    cellHeight = CGRectGetMaxY(imageRect);
    return self;
}
//返回细胞的高度
-(CGFloat)cellHeight{
    return cellHeight;
}

@end
